package appconfig

import (
	"fmt"
	"github.com/spf13/viper"
)

type Appconfig struct {
	Mysql
	Redis
}
type Mysql struct {
	User     string
	Password string
	Host     string
	Port     int
	Database string
}
type Redis struct {
	Password string
	Host     string
	Port     int
	Database int
}

var Appconf Appconfig

func Init() {
	viper.SetConfigFile("../appconfig/dev.yaml")
	err := viper.ReadInConfig()
	if err != nil {
		panic(err)
	} else {
		fmt.Println("动态配置连接成功")
	}
	err = viper.Unmarshal(&Appconf)
	if err != nil {
		panic(err)
	} else {
		fmt.Println(Appconf)
	}
}
